<?php
/**
 * Created by PhpStorm.
 * User: liyang
 * Date: 2017/12/6  Time: 下午3:49
 * Description: 处理测评
 */

namespace Service;

use UserVerifaceRecordModel;

class ConsulationService extends BaseService
{

    /**
     * @desc 预约记录
     * @param $info
     * @return array
     */
    public function getConsulationData($info)
    {
        $i = 0;
        $data = [];
        foreach ($info as $v) {
            $consultationList = UserVerifaceRecordModel::find($v->id)->hasManyConsultation()->get();
            if ($consultationList->isEmpty()) {
                continue;
            }
            foreach ($consultationList as $vv) {
                $data['list'][$i]['fund_name'] = $vv->title;
                $data['list'][$i]['subscribe'] = '已预约';
                $data['list'][$i]['subscribe_time'] = $vv->ctime;
                $data['list'][$i]['id'] = $vv->id;
                $data['list'][$i]['pid'] = $vv->pid;
                $data['list'][$i]['name'] = $vv->name;
                $data['datetime'][] = date("YmdHis", strtotime($vv->ctime));
                $data['pid'][] = $vv->pid;;
                $i++;
            }
        }
        return $data;
    }

    public static function hasConsulation($uid, $fid)
    {
        $vs = UserVerifaceRecordModel::query()->where(['uid' => $uid, 'pid' => $fid])->get();
        if ($vs->isEmpty()) {
            return false;
        }
        /** @var  UserVerifaceRecordModel $v */
        foreach ($vs as $v) {
            $consultationList = $v->hasManyConsultation()->get();
            if (!$consultationList->isEmpty()) {
                return true;
            }
        }

        return false;
    }

    public static function clearPrivateStatus($uid)
    {
        $date = date('Y-m-d H:i:s');
        \UserPrivateModel::query()
            ->where(['uid' => $uid])
            ->whereIn('private_reserve_status', [3,4,6])
            ->update(['private_reserve_status'=>1, 'update_time' =>$date]);
        UserVerifaceRecordModel::query()
            ->where(['uid' => $uid, 'auth_result' => 2])
            ->update(['auth_result' => 1, 'update_time' =>$date]);
    }
}
